import java.awt.*;
import java.time.Period;

public class Solution
{

    /**
     * 普通实现链表反转
     */
    public ListNode reverseList(ListNode head) {

        ListNode prev = null;
        ListNode cur = head;
        while (cur != null){
            ListNode next = cur.next;
            cur.next = prev;
            prev = cur;
            cur = next;
        }
        return prev;
    }

    /**
     * 递归实现链表反转
     * @param head
     * @return
     */
    public ListNode reverseLists(ListNode head){
       if (head == null || head.next == null){
           return head;
       }

        ListNode newHead = reverseLists(head.next);
        System.out.println(newHead.toString());
       head.next.next=head;
       head.next = null;
       return newHead;
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5};
        ListNode listNode = new ListNode(arr);
        ListNode listNode2 = new Solution().reverseLists(listNode);
        System.out.println(listNode2.toString());
    }
}
